% This m-file is to produce the Qz-dependence 1D fluorescing data

MATfile={
    %'sph02_scan406_raw.mat';     % bar 3 KCl 100 mM, FeCl3 5 mM
    
    'sph02_scan36_raw.mat';       % bar 3  SPM/KCl/FeCl3 pH 2
    'sph02_scan224_raw.mat';      % bar 3  SPM/KCl/FeCl3 pH 3
    'sph01_scan329_raw.mat';      % bar ?  SPM/KCl/FeCl3 pH 4
    'sph02_scan101_raw.mat';      % bar 3  SPM/KCl/FeCl3 pH 5
    'sph01_scan259_raw.mat';      % bar 3  SPM/KCl/FeCl3 pH 7.1
   

        %'sph02_scan442_raw.mat';     % bar 2  KCl 100 mM, FeCl3 5 mM
%         'sph01_scan185_raw.mat';    %  bar 2  SPM/KCl/FeCl3 pH 3
%         'sph02_scan144_raw.mat';    %  bar 2 SPM/KCl/FeCl3 pH 5
%         'sph01_scan301_raw.mat';    %  bar 2  SPM/KCl/FeCl3 pH 7.1
     %   'sph02_scan14_raw.mat';      %  bar 2  SPM/KCl/FeCl3 pH 4
    }

ch=[1:2048];
CalibCoef=[0.0089,-0.0048];  % Channel->Energy calibration coefficients APS detector
E=ch*CalibCoef(1)+CalibCoef(2);
Emax=14;
Emin=13.474
EM=1;
EN=2048;
for k=1:length(E)
    if E(k)>Emin;EM=k-1;break;
    end
end

for k=1:length(E)
    if E(k)>Emax;EN=k-1;break;
    end
end

MarkerType={'o','s','v','^','d','>','<'}
COLOR={'k','r','b',[0 0.4 0],'m','k','k'}

%COLOR={'r','b',[0 0.4 0],'m','k','k'}



%%
close all
figure

hold on
%  Note:qz=0.010-0.035. qz(9)=0.018; 

I0=1e6;
I_mon=1e5;
for k=1:length(MATfile)
    data=load(MATfile{k});
    temp=data.mca(:,1:11);
    temp_err=sqrt(temp);
    
    MON=data.mon(1:11)/I_mon;
    CT=data.ct(1:11)/15;
    % COMMENTS: Monitor and Counting time are almost same.
   
    

    Intensity1D=sum(temp,2);
    Intensity1D_err=sqrt(sum(temp_err.^2,2));

%     Intensity1D=I0*temp/MON/CT;
%     Intensity1D_err=I0*temp_err/MON/CT;
    H=ploterr(E,Intensity1D,[],Intensity1D_err,MarkerType{k},'hhy',0.1);
    set(H,'LineWidth',3,'color',COLOR{k},'MarkerSize',12,'MarkerFaceColor','w');
end
hold off
set(gca,'xlim',[6 13.7])
set(gca,'xtick',[6:0.5:13.6]);
set(gca,'ylim',[-5 205]);
set(gca,'LineWidth',3,'box','on');
set(gca,'FontSize',30,'FontName','times');
breakxaxis([7.3 12.9],0.015);





        
        
        